
//Copyright 1997-2009 Syrinx Development, Inc.
//This file is part of the Syrinx Web Application Framework (SWAF).
// == BEGIN LICENSE ==
//
// Licensed under the terms of any of the following licenses at your
// choice:
//
//  - GNU General Public License Version 3 or later (the "GPL")
//    http://www.gnu.org/licenses/gpl.html
//
//  - GNU Lesser General Public License Version 3 or later (the "LGPL")
//    http://www.gnu.org/licenses/lgpl.html
//
//  - Mozilla Public License Version 1.1 or later (the "MPL")
//    http://www.mozilla.org/MPL/MPL-1.1.html
//
// == END LICENSE ==
using System;

using Swaf;

namespace Swaf.BizObj
{
	/// <summary>
	/// This exception is thrown when someone attempts to create a BusinessObject 
	/// of a non-existant type.</summary>
	[Serializable]
	public class BadBizObjTypeException: BaseException
	{
		public BadBizObjTypeException(string bizObjType):base(bizObjType + ": no such BusinessObject type")
		{
			//Common.writeLog("Throwing " + this);
			// printStackTrace(Common.logFile());
		}
		public BadBizObjTypeException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context)
		{
		}

	}

	/// <summary>This exception is thrown whenever a validator cannot be parsed.
	/// </summary>
	[Serializable]
	public class ParseError : BaseException
	{
		public ParseError(string message):base(message)
		{
			//Application.currentApp.Log.println("Throwing " + this);
		}

		public ParseError(string message, Exception innerException):base(message, innerException)
		{
			//Application.currentApp.Log.println("Throwing " + this);
		}
		
		public ParseError(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context)
		{
		}
	}

	/// <summary>This exception is thrown whenever a biz obj cursor tries to navigate to a position that is out of range.
	/// </summary>
	[Serializable]
	public class IndexOutOfRangeException : BaseException
	{
		public IndexOutOfRangeException(string message):base(message)
		{
			//Application.currentApp.Log.println("Throwing " + this);
		}
		
		public IndexOutOfRangeException(string message, Exception innerException):base(message, innerException)
		{
			//Application.currentApp.Log.println("Throwing " + this);
		}

		public IndexOutOfRangeException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context)
		{
		}
	}

	/// <summary>This exception is returned and/or thrown when a field name and/or
	/// value is considered to be invalid.
	/// </summary>
	[Serializable]
	public class BadBizObjFieldException:BaseException
	{
		public BadBizObjFieldException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context)
		{
		}
		public override string Message
		{
			get
			{
				return String.Format("{0}.{1}:{2}", bizObj_ == null?bizObjType_:bizObj_.type.Name, name_, details_);
			}
			
		}
		public virtual string MessageLastPart
		{
			get
			{
				return details_;
			}
			
		}
		public BadBizObjFieldException(IBizObj bizObj, string name, string details):base(bizObj.type.Name + "." + name + ": " + details)
		{
			bizObj_ = bizObj;
			name_ = name;
			details_ = details;
			//Common.writeLog("Bad field found: " + this.Message);
			// this.printStackTrace(Common.logFile());
		}
		public BadBizObjFieldException(string bizObjType, string name, string details): base(bizObjType + "." + name + ": " + details)
		{
			bizObjType_ = bizObjType;
			name_=name;
			details_=details;
		}
		public virtual IBizObj bizObj()
		{
			return bizObj_;
		}
		public virtual string bizObjType()
		{
			return bizObj_.type.Name;
		}
		public virtual string fieldName()
		{
			return name_;
		}
		protected internal IBizObj bizObj_;
		protected internal string name_;
		protected internal string details_;
		protected internal string bizObjType_;
	}

}